import axios from "axios";
import { ElMessage } from "element-plus";

// 创建axios实例
const instance = axios.create({
  // 超时时间
  timeout: 1000,
  // 请求头设置
  headers: { "Content-Type": "application/json" },
  // params: {
  //   token: localStorage.getItem("token"),
  // },
});


const http = {
  get(url: string, params?: object) {
    return instance
      .get(url, {
        params: params,
      })
      .then((res) => {
        return res;
      })
      .catch((err) => {
        ElMessage.error(err.message);
      });
  },
  post(url: string, data?: object) {
    return instance
      .post("http://www.pudge.wang:3080/api" + url, data)
      .then((res) => {
        return res;
      })
      .catch((err) => {
        ElMessage.error(err.message);
      });
  },
};

export default http;
